Add time based update for caching in fs.wrap.WrapCachedDir#140
Add time based update for caching in fs.wrap.WrapCachedDir#140media-proxy wants to merge 11 commits intoPyFilesystem:masterfrom
Conversation
2 similar comments
|
A second question here, is it necessary to use a threading.Lock() for the caching dict? |
|
Third question, why not using Cached listdir here ? |
|
OK, here all Questions in a row:
|
|
This looks interesting. I'm afraid I'm going away on holiday tomorrow for 3 weeks. Will take a look when I get back... |
|
Sorry for the delay, haven't been back long.
To be honest, I'm not convinced the 'live time' functionality is useful enough to be supported feature in the cache dir. The only time you would need to refresh the cache, is if some other process is writing to the filesystem. Then the live time becomes somewhat arbitrary. Even 10 seconds is enough for the filesystem to get out of sync with the cache. So I wouldn't want to overload the CacheDir with this functionality. If its to go in the main lib I would favour it being a different class, perhaps extending CacheDir. Thanks for the input, but I don't think I'm going to merge this one. You have highlighted that CacheDir needs some work. I'll put that on the to do list... |
| with self.assertRaises(errors.ResourceNotFound): | ||
| fs.getinfo('/foofoo') | ||
|
|
||
| def test_cachedir_time(self): |
There was a problem hiding this comment.
Are you familiar with https://github.com/spulec/freezegun ? You can get rid of those sleep in tests.
|
Hi Will, thank you for your reply. I was also on holiday, so sorry for the late reply. Tere are 2 Ideas behind Livetime:
Another Idea could be to implement a refresh function inside the filesystem. So the external app coud decide when the update should happen. It would be ok for me to create an extended cache Object based on this. Thank you for the tip with freezegun, I didn't hear about this until now. |
A new feature for WrapCachedDir:
livetime: after this time a cached entry is too old and will be recached
speedup: the cache time of uptodate entries will be renewed, so cached entries with many accesses will be delivered from cache more often.
Todo:
cleanup old entries from time to time
Question:
The scandir implementation does not use the page parameter for cache_key, so I think there will bethe same result if you call scandir with page=1 first and page=None secondly.
An Idea is to generate cache_key like:
cache_key = (_path, frozenset(namespaces or ()), path)
Am I right?